package domain;

import java.util.List;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;

import database.access.layer.RecommenderDal;

public class Recommendation {
	private RecommenderDal recommenderDal = null;
	
	public Recommendation(){
		this.recommenderDal = new RecommenderDal();
	}
	
	public List<RecommendedItem> recommend (int userId, int howManyRecommendation) throws TasteException{
		
		UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(recommenderDal.getDataModel());
    	UserNeighborhood neighborhood =
    	          new NearestNUserNeighborhood(3, userSimilarity, recommenderDal.getDataModel());
    	Recommender recommender =
    	          new GenericUserBasedRecommender(recommenderDal.getDataModel(), neighborhood, userSimilarity);
    	Recommender cachingRecommender = new CachingRecommender(recommender);
    	List<RecommendedItem> recommendations =
  	          cachingRecommender.recommend(userId, howManyRecommendation);
    	
    	return recommendations;
	}
}
